package com.gomtel.smartdevice.base;

import com.gomtel.smartdevice.di.component.ActivityComponent;
import com.gomtel.smartdevice.di.component.DaggerActivityComponent;
import com.gomtel.smartdevice.di.moudle.ActivityModule;
import com.gomtel.smartdevice.global.WatchApplication;
import com.gomtel.smartdevice.moudle.DataManager;
import com.gomtel.smartdevice.moudle.event.CommonEvent;
import com.gomtel.smartdevice.moudle.rxtools.EventBusUtil;
import com.gomtel.smartdevice.utils.ToastUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import javax.inject.Inject;

/**
 * Created by Administrator on 2018/5/14 0014.
 */

public abstract class WatchAppBaseActivity extends SimpleActivity{

    @Inject
    public ToastUtil toastUtil;

    @Inject
    public DataManager dataManager;

    protected ActivityComponent getActivityComponent() {
        return DaggerActivityComponent.builder()
                .appComponent(WatchApplication.getAppComponent())
                .activityModule(new ActivityModule(this))
                .build();
    }

    @Override
    protected void onViewCreated() {
        super.onViewCreated();
        EventBusUtil.register(this);
        initInject();
    }

    protected abstract void registerEvent(CommonEvent commonevent);

    protected abstract void initInject();

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventBusCome(CommonEvent event) {
        if (event != null) {
            registerEvent(event);
        }
    }

    protected void receiveStickyEvent(CommonEvent event) {

    }

    @Override
    protected void onUnSubscribe() {
        super.onUnSubscribe();
        EventBusUtil.unregister(this);
    }
}
